package com.wzcl.app.dao.repository;

import com.wzcl.app.dao.model.UserInfo;
import com.wzcl.app.dao.model.UserTopUp;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface UserTopUpRepository extends JpaRepository<UserTopUp,Integer>, JpaSpecificationExecutor<UserInfo> {
    //根据用户电话查询充值信息
    UserTopUp findAllByUserPhone(String userPhone);

    //根据用户手机更新学币信息
    @Modifying
    @Query(value = "update UserTopUp u set u.learnCoinSurplus = ?1, u.topUpMoney = ?2 where u.userPhone = ?3")
    @Transactional
    void updateUserTopUpByPhone(Double learnCoinSurplus, Double topUpMoney, String userPhone);

    //根据用户手机更新学币信息
    @Modifying
    @Query(value = "update UserTopUp u set u.learnCoinSurplus = ?1 where u.userPhone = ?2")
    @Transactional
    void updateUserTopUpByUserPhone(Double learnCoinSurplus, String userPhone);

    //查询学币信息
    @Query(value = "select u.learnCoinSurplus from UserTopUp u where u.userPhone = ?1")
    Double findLearnCoinByUserPhone(String userPhone);
}
